cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0048 NEW)
project(pak VERSION 2.0.2 LANGUAGES C)
option(LGPL "Use custom startfiles on windows for smaller binary, requiring GNU Lesser General Public License 2.1+." ON)
if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release." FORCE)
endif (NOT CMAKE_BUILD_TYPE)
if (MSVC)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT /wd4996 /wd4068")
    set(CompilerFlags
            CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
            CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE)
    foreach (CompilerFlag ${CompilerFlags})
        string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
    endforeach ()
endif ()
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
    set(CMAKE_C_FLAGS "-O3 -pipe -Wall -Wextra -fmerge-all-constants -Wl,--gc-sections,--build-id=none -Wno-format-extra-args -Wno-unused-result")
    set(CMAKE_C_FLAGS_DEBUG "-g")
    set(CMAKE_C_FLAGS_RELEASE "-O3 -s -g0 -DNDEBUG")
    set(CMAKE_CPP_FLAGS_RELEASE "-O3 -s -g0 -DNDEBUG")
    set(CMAKE_CXX_FLAGS_RELEASE "-O3 -s -g0 -DNDEBUG")
    set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-O3")
    set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "-Wl,-O3")
    if (WIN32 AND LGPL)
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles -D_LGPL")
    endif ()
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -Wl,-O3")
endif ()
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} DIR_SRCS)
add_executable(pak ${DIR_SRCS})
